package br.edu.ufcg.dsc.psoo.mymoney.model.bean;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.mentawai.bean.BeanBase;

/**
 * Bean de tipo <br>
 * Anotado com configura��es do <b>Hibernate</b>
 * 
 * @author leonardo
 * @version 1.0
 */
@Entity
@Table(name = "types", schema = "psoo")
public class Type extends BeanBase implements Serializable {

	@Transient
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private Long id;

	@Column(name = "name", nullable = false, length = 60)
	private String name;

	@ManyToOne(fetch = FetchType.EAGER, targetEntity = User.class)
	@JoinColumn(name = "users_id", insertable = true, updatable = true)
	@Fetch(FetchMode.JOIN)
	private User user;

	@OneToMany(mappedBy = "type", fetch = FetchType.LAZY, targetEntity = Movement.class)
	@Cascade(CascadeType.SAVE_UPDATE)
	private Collection<Movement> movements;

	public Type() {
	}

	/**
	 * @return the movements
	 */
	public Collection<Movement> getMovements() {
		return movements;
	}

	/**
	 * @param movements
	 *            the movements to set
	 */
	public void setMovements(Collection<Movement> movements) {
		this.movements = movements;
	}

	/**
	 * @return the serialVersionUID
	 */
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public Type(String name, User user) {
		this.name = name;
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Type(Long id) {
		this.id = id;
	}

	public String toString() {
		return name;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}